package com.example.mvc.controller;

import com.example.mvc.bean.Brand;
import com.example.mvc.service.BrandService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/selectAllServlet")
public class SelectAllServlet  extends HttpServlet {
    private BrandService service =  new BrandService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //查询数据
        List<Brand> brands = service.selectAll();
        if (brands!=null){
            //存到request属性
            request.setAttribute("brands",brands);
            //转发到view显示
            request.getRequestDispatcher("/brand.jsp").forward(request,response);

        }else {
            System.out.println("查不到数据");
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        this.doGet(req,resp);
    }
}
